<?php
Yii::import('user.models.User');

class WebUser extends CWebUser
{
    private $_model=null;
    private static  $rolesNames=array(
        '0'=>'guest',
        '1'=>'user',
        '2'=>'moderator',
        '3'=>'admin',
        '4'=>'banned',
    );

    public function getRole()
    {
        if($user=$this->getModel()) return self::$rolesNames[$user->role];
        return null;
    }

    public function getRoleId()
    {
        if($user=$this->getModel()) return $user->role;
        return null;
    }

    private function getModel(){
        if(!$this->isGuest && $this->_model===null) $this->_model=User::model()->findByPk($this->id,array('select'=>'role'));
        return $this->_model;
    }
}